#include "ws_handler.hpp"
#include "../utils/logger.hpp"

void WebSocketHandler::handleMessage(const std::string &message)
{
    // 处理 WebSocket 消息帧
    Logger::info("WebSocket message received: {}", message);
    // 示例：简单回显消息
    send(message);
}

void WebSocketHandler::onConnection(const TcpConnectionPtr &conn)
{
    // 处理 WebSocket 握手
    Logger::info("Performing WebSocket handshake with client: {}", conn->getPeerAddress().toIpPort());
    // 示例：发送握手响应
    conn->send("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n");
}

void WebSocketHandler::send(const std::string &message)
{
    // 实现 WebSocket 帧封装并发送
    Logger::info("Sending WebSocket message: {}", message);
}